package com.firefly.web.controller.admin.ums;

import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.ums.RoleAdminDto;
import com.firefly.dao.dto.ums.RoleDto;
import com.firefly.dao.dto.ums.RoleMenuDto;
import com.firefly.dao.dto.ums.RoleQueryDto;
import com.firefly.dao.vo.ums.RoleAdminVo;
import com.firefly.dao.vo.ums.RoleListVo;
import com.firefly.dao.vo.ums.RolePermissionVo;
import com.firefly.dao.vo.ums.RoleVo;
import com.firefly.service.command.ums.RoleCommand;
import com.firefly.service.query.ums.RoleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;


/**
 * @description: 角色管理控制器
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/07/15
 **/
@ConsoleApiRestController("role")
public class RoleController {
    private final RoleQuery roleQuery;
    private final RoleCommand roleCommand;

    @Autowired
    public RoleController(RoleQuery roleQuery, RoleCommand roleCommand) {
        this.roleQuery = roleQuery;
        this.roleCommand = roleCommand;
    }

    @GetMapping("/list")
    public RoleListVo getList(RoleQueryDto roleList) {
        return roleQuery.getList(roleList);
    }

    @GetMapping("/detail")
    public RoleVo getDetail(@Validated(RoleQueryDto.showDetail.class) RoleQueryDto role) {
        return roleQuery.getDetail(role.getDetailId());
    }

    @GetMapping("/priv")
    public List<RolePermissionVo> getPriv(@Validated(RoleQueryDto.showDetail.class) RoleQueryDto role) {
        return roleQuery.getPriv(role);
    }

    @GetMapping("/admins")
    public List<RoleAdminVo> getAdmins(@Validated(RoleQueryDto.showDetail.class) RoleQueryDto role) {
        return roleQuery.getAdmins(role);
    }

    @PostMapping("/create")
    public Boolean postCreate(@Validated(RoleDto.create.class) RoleDto request) {
        return roleCommand.create(request);
    }

    @PostMapping("/update")
    public Boolean postUpdate(@Validated(RoleDto.update.class) RoleDto request) {
        return roleCommand.update(request);
    }

    @PostMapping("/status")
    public Boolean postUpdateStatus(@Validated(RoleDto.status.class) RoleDto request) {
        return roleCommand.updateStatus(request);
    }

    @PostMapping("/remove")
    public Boolean postRemove(@Validated(CommonDto.showDetail.class) CommonDto request) throws Exception {
        return roleCommand.remove(request);
    }

    @PostMapping("/removemultiple")
    public Boolean postRemoveMultiple(@Validated(CommonDto.removeMultiple.class) CommonDto request) throws Exception {
        return roleCommand.removeMultiple(request);
    }


    @PostMapping("/priv")
    public Boolean postPriv(@Validated RoleMenuDto request) {
        return roleCommand.postPriv(request);
    }

    @PostMapping("/removeadmin")
    public Boolean postRemoveAdmin(@Validated RoleAdminDto request) {
        return roleCommand.postRemoveAdmin(request);
    }
}

